package com.broheim.websocket.core.endpoint.server;

import com.broheim.websocket.core.endpoint.EndpointConfig;
import com.broheim.websocket.core.endpoint.EndpointCreator;
import com.broheim.websocket.core.publisher.DefaultEventPublisher;
import com.broheim.websocket.core.publisher.EventPublisher;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Setter
@Getter
public class WebSocketServer extends EndpointConfig {

    private static Map<String, EventPublisher> completePublisher = new ConcurrentHashMap<>();

    private EndpointCreator endpointCreator = new EndpointCreator();

    public static EventPublisher builderPublisher(String path) {
        EventPublisher eventPublisher = completePublisher.get(path);
        if (null != eventPublisher) {
            return eventPublisher;
        }
        eventPublisher = new DefaultEventPublisher(urlListener.get(path));
        completePublisher.put(path, eventPublisher);
        return eventPublisher;
    }

}
